<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/commons.jsp" %>
<html>
	<head>
		<title>微博搜索</title>
		<link rel="stylesheet" type="text/css" href="${ctx }/css/style.css" />
		<link rel="stylesheet" type="text/css" href="${ctx }/css/thickbox.css" />
		<script type="text/javascript" src="${ctx }/js/jquery.js"></script>
		<script type="text/javascript" src="${ctx }/js/thickbox.js"></script>
		<script type="text/javascript" src="${ctx }/js/weibo.js"></script>
		<script type="text/javascript">
			$(function(){//就绪函数：就绪-文档（HTML文档）就绪
				var ctx = $("#ctx").attr("title");
				var search = $("#search").attr("title");
				$.ajax({
					url: ctx + "/searchUser",
					type: "post",
					data: {"search":search},
					success: function(data){
						var jsondata = jQuery.parseJSON(data);
						$("ul#userlist").empty();
						$.each(jsondata, function(i, item){
						//	sleep(100);
							if(i<3){
							    $("<div>").load(ctx+"/user.jsp #tempul", item, function(){
							    	$("ul#userlist").append($(this).find("#tempul").html());
							    });
							}else {
								$("#search_user_more").show();
								return false;//退出each循环
							}
						});
						$("#search_user").show();
					}
				});
				sleep(100);
				$.ajax({
					url: ctx + "/searchWeibo",
					type: "post",
					data: {"search":search},
					success: function(data){
						var jsondata = jQuery.parseJSON(data);
						$("ul#weibolist").empty();
						$.each(jsondata, function(i, item){
							sleep(100);
						    $("<div>").load(ctx+"/weibo.jsp #tempul", item, function(){
						    	$("ul#weibolist").prepend($(this).find("#tempul").html());
						    });
						});
				    	$.getScript(ctx+"/js/init.js");
						$('#loading').hide();
					}
				});
			});
			function sleep(timeMillis) { 
				var now = new Date();
				var exitTime = now.getTime() + timeMillis;  
				while (true) { 
				    now = new Date(); 
				    if (now.getTime() > exitTime){
				     return;
				    }
				}
			}
		</script>
	</head>
	<body> 
		<span id="ctx" title="${ctx }"></span>
		<span id="search" title="${param.search }"></span>
		<c:if test="${sessionScope.user eq null}">
			<c:redirect url="/index.jsp" />
		</c:if>
		<div id="wrap">
			<div id="global_header">
				<div class="content">
					<a href="${ctx }/${sessionScope.user.id }">首页</a>
					<a href="${ctx }/${sessionScope.user.id }/profile">我的微博</a>
					<a href="${ctx }/settings/avatar">设置头像</a>
					<a href="${ctx }/logout">退出</a>
					<input class="search_input" type="text" />
					<a id="search_btn" href="javascript:;">搜索</a>
				</div>
			</div>
			<div id="container">
				<div id="main">
					<div id="content">
						<div id="left">
							<div class="avatar">
								<img class="avatar" src="${ctx }/avatar/${sessionScope.user.avatar }" width="50" />${sessionScope.user.nick }
							</div>
						</div>
						<div id="center">
							<div id="search_user">
								<ul id="userlist">
								</ul>
								<div id="search_user_more"><a href="javascript:search_user('${param.search }');">更多&gt;&gt;</a></div>
								<div class="clear"></div>
							</div>
							<div class="clear"></div>
							<div id="search_weibo">
								<div id='loading'><span>正在加载，请稍候...</span></div>
								<ul id="weibolist">
								</ul>
							</div>
						</div>
						<div id="right">
							right...
						</div>
						<div class="clear"></div>
					</div>
				</div>
			</div>
			<div id="global_footer">
				footer...
			</div>
		</div>
		<div id="emotion_layer">
			emotion_layer...
		</div>
	</body>
</html>
